from common.base import Base,By,open_browser,sleep
class BuyerLoginPage(Base):
    # 类属性：元素定位器
    username_loc = (By.NAME, 'login_info')
    password_loc = (By.NAME, 'password')
    remember_loc = (By.NAME,'remember')
    submit_loc = (By.CLASS_NAME, 'submit_login')
    log_status_loc=(By.CLASS_NAME, 'f14')#会员中心，欢迎语元素
    # 方法：针对元素的操作
    def input_username(self,username):
        self.send_keys(BuyerLoginPage.username_loc,username)
    def input_password(self,password):
        self.send_keys(BuyerLoginPage.password_loc, password)
    def remember_password(self):
        self.click(BuyerLoginPage.remember_loc)
    def click_login(self):
        self.click(BuyerLoginPage.submit_loc)
    def is_success_login(self,txt):
        text = self.get_element_text(BuyerLoginPage.log_status_loc)
        if txt == text:
            return True
        else:
            return False

if __name__ == '__main__':
    login = BuyerLoginPage(open_browser())
    login.get_url('http://172.16.0.137/shop/index.php?controller=simple&action=login')
    login.input_username('ceshi2001')
    login.input_password('ceshi2001')
    login.remember_password()
    sleep(3)
    login.click_login()
    sleep(3)
    login.driver.quit()